<?

include_once("private.inc.php");

class Event {
  private $id;
  private $owner;
  private $name;
  private $description;
  private $location;
  private $start_time;
  private $end_time;
  
  function getID() {
    return $this->id;
  }
  
  function setID($id) {
    $this->id = $id;
  }
  
  function getOwner() {
    return $this->owner;
  }
  
  function getOwnerID() {
    $owner = $this->getOwner();
    if (empty($owner)) return 0;
    return $owner->getID();
  }
  
  function setOwner($owner_id) {
    if (empty($owner_id)) {
      $this->owner = NULL;
      return;
    }
    
    $query = "SELECT * FROM `".USER_TABLE."` WHERE `id`=".$owner_id.";";
    $result = mysql_query($query) or die(mysql_error());
    if ($line = mysql_fetch_assoc($result)) {
      $owner = new User();
      $owner->setAttributes($line);
      $this->owner = $owner;
    }
    else {
      $this->owner = NULL;
    }
  }
  
  function getName() {
    return $this->name;
  }
  
  function setName($n) {
    $this->name = $n;
  }
  
  function getDescription() {
    return $this->description;
  }
  
  function setDescription($d) {
    $this->description = $d;
  }
  
  function getLocation() {
    return $this->location;
  }
  
  function setLocation($l) {
    $this->location = $l;
  }
  
  function getStartTime() {
    return $this->start_time;
  }
  
  function setStartTime($st) {
    $this->start_time = $st;
  }
  
  function getEndTime() {
    return $this->end_time;
  }
  
  function setEndTime($et) {
    $this->end_time = $et;
  }
  
  function setAttributes($array) {
    $this->setID($array['id']);
    $this->setOwner($array['owner_id']);
    $this->setName($array['name']);
    $this->setDescription($array['description']);
    $this->setLocation($array['location']);
    $this->setStartTime($array['start']);
    $this->setEndTime($array['done']);
  }
}

?>
